<?php
/*
 * JAdmin_core.php
 * name:xiaojia
 * email:iatt@qq.com
 * qq:273142650
 * time:2011.9.19 16:11
*/
	class JAdmin_core
	{
		
		static function init()
		{
			
			self::php_ini();
			
			define('DATABASE_SERVER', '192.168.1.40:3306');          //数据库地址
			
			define('DATABASE_USERNAME', 'root');                     //数据库用户名
			
			define('DATABASE_PASSWORD', '900219');                   //数据库密码
			
			define('DATABASE_TABLE', 'agricultural');	             //数据库名
			
			define('TIP_TIME', 1);                                   //提示页停留时间
			
			define('PRE', 'agricultural_a_');                        //前缀
			
			define('REFERER', @$_SERVER['HTTP_REFERER']);            //来访页
			
			define('ACTION', 'interface.php');                       //FORM提交地址
			
			define('FORMHASH', 'webos_hash');
			
			define('JSACTION', 'control/interface.php');
			
			define('TEMPLATE_HEADER', 'resources/model/public/head.php');
			
			define('TEMPLATE_FOOTER', 'resources/model/public/foot.php');
			
			define('APPLICATION_CONFIG', 'control/interface.php?action=webos&amp;mod=get-app-config');
			
		}
		
		static function php_ini()
		{
			
			ob_start();
			
			session_start();
			
			ini_set('display_errors', 1); //错误
			
			ini_set('date.timezone', 'Asia/Shanghai'); //时区
			
		}
		
		static function member()
		{
			
			global $_G;
			
			if (self::check_login()) {
				
				$webosuser = Jdb::select("SELECT * FROM " . PRE . "webosuser WHERE userID = $_G[uid]");
				
				if (empty($webosuser['userID'])) {
					
					$webosuser = self::reg_webosuser($_G['uid']);
					
				}
				
				$_G['webos_screen'] = $webosuser['userDefaultScreen'];
								
				$_G['webos_theme'] = $webosuser['userTheme'];
				
				$_G['webos_themewidth'] = $webosuser['userThemeWidth'];
				
				$_G['webos_themeheight'] = $webosuser['userThemeHeight'];
				
				$_G['webos_search'] = $webosuser['userSearch'];
				
				$_G['webos_inputmethod'] = $webosuser['userInputMethod'];
				
				$_G['webos_group_file'] = $webosuser['userGroupFile'];
				
				$_G['webos_userBgSound'] = $webosuser['userBgSound'];
				
				$_G['webos_group'] = $webosuser['userGroup'];
				
			}
			
			return $_G;
			
		}
		
		static function reg_webosuser($uid)
		{
		
			Jdb::select("CALL " . DATABASE_TABLE . ".regWebosUser($uid)");
			
			return Jdb::select("SELECT * FROM " . PRE . "webosuser WHERE userID = $uid");
			
		}
		
		static function formHASH()
		{
			
			global $USER;
			
			$hash = substr(md5(rand() . date('Y-m-d H:i:s')), 15, 5);
			
			$_SESSION[FORMHASH] = $hash;
			
			return $hash;
			
		}
		
		static function HASH($hash)
		{
			
			global $USER;
			
			if ($hash == $_SESSION[FORMHASH]) {
				
				$_SESSION[FORMHASH] = '';
				
				return true;
				
			} else {
				
				$_SESSION[FORMHASH] = '';
				
				return false;
				
			}
			
		}
		
		static function check_login()
		{
			
			global $_G;
			
			$_G['uid'] <= 0 ? $ret = false : $ret = true;
						
			return $ret;
			
		}
		
	}
?>